ostree/trivial-httpd: Fix --autoexit with --daemonize and --log-file
authorDan Nicholson <nicholson@endlessm.com>
Fri, 18 Oct 2019 16:33:02 +0000 (10:33 -0600)
committerDan Nicholson <nicholson@endlessm.com>
Fri, 24 Jan 2020 20:11:54 +0000 (13:11 -0700)
commitfbf5a94e0aa2d55203ac03fa941a28ce9f6ba071
treeafe79d6c2e6afeb31fa9b6a9de013cbf3d996721
parent8cc81126a1254cda340f2ab145eb8247bad3ce35
ostree/trivial-httpd: Fix --autoexit with --daemonize and --log-file

When --autoexit is used with --daemonize and --log-file, the program
never exits when the root directory is deleted. I believe what happens
is that g_file_new_for_path triggers the glib worker context to be
started to talk to GVfs. Once the program forks, the parent exits and
the thread iterating the worker context is gone. The file monitor then
never receives any events because the inotify helper also runs from the
worker context.

Move the fork earlier just after parsing and validating the command line
arguments. In order to handle setup errors in the child, a pipe is
opened and the parents waits until the child writes a status byte to it.
If the byte is 0, the parent considers the child setup successful and
exits and the child carries on as a daemon. Notably, the child doesn't
reopen stderr to /dev/null until after this so that it can send error
messages there.

Fixes: #1941
src/ostree/ostree-trivial-httpd.c